<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
		<title>牛只列表</title>
		<link href="css/home.page.css" rel="stylesheet" />
		<link href="css/new_file.css" rel="stylesheet" type="text/css">
		<link href="css/mui.min.css" rel="stylesheet" type="text/css">
		
		<script charset="UTF-8" src="js/config.js"></script>
		<script charset="UTF-8" src="js/testActivityName.js"></script>
		<script charset="UTF-8" src="js/core.js"></script>
		<script charset="UTF-8" src="js/cipher-core.js"></script>
		<script charset="UTF-8" src="js/tripledes.js"></script>
		<script charset="UTF-8" src="js/mode-ecb.js"></script>
		<script src="js/jquery-1.8.3.min.js"></script>
		<script type="text/javascript" src="js/zepto.min.js"></script>
		<script type="text/javascript" src="js/spin.min.js"></script>
		<script charset="UTF-8" src="js/mui.min.js"></script>
		<script src="js/echarts.min.js"></script>
	</head>
	<style>
		.mui-bar{
			     padding-right: 0px; 
			     padding-left:0px; 
		}
	</style>
	<body style="background: #f5f5f6; padding-bottom: 50px;">
	<div class="spin"></div>
	<header id="header" class="mui-bar mui-bar-transparent" style="width: 100%;">
			<div class="head-zhjf" style="width: 100%;">
				<img onclick="CattleReturn()" src="images/fanhui@3x.png" class="ryjk-tx">
				<p>掉落管理</p>
			</div>
	</header>
		<div class="jnx-index-search" style="margin-top: 40px;">
			<div style="margin-top: 15px; ">
				<div class="jnx-idx-cd-a" onclick="Mating()" >
					<span style="">未处理</span>
				</div>
				<div class="jnx-idx-cd-a" >
					<span style="">已处理</span>
					<div class="qiehuan-indx"></div>
				</div>
			</div>
		</div>
		<div style="margin-top: 10px;" class="clear"></div>
		<div >
			<div id="noApplicationRecord">
				<div style="width: 100%;height: 100%;text-align: center;margin-top: 45%;">
					<img src="images/nodata.png" style="width: 200px;height: 140px;"/>
				</div>
			</div>
		</div>
		<div id="hddb" style="position: fixed;right: -63px;bottom: 30px;border-radius: 25px;width: 50px;height: 50px;text-align: center;">
			<img src="img/hddb.png" style="width: 32px;height: 32px;    margin-top: 9px;" onclick="goTop()">
		</div>
		
		<script>
			var CattleSeachData = JSON.parse(localStorage.getItem('CattleSeachData'));
			console.log(CattleSeachData)
			var numberStr = 2;
			var butStr = 0;
			var noApplicationRecord = document.getElementById('noApplicationRecord');
			console.log(noApplicationRecord)
			var equipmentData = JSON.parse(localStorage.getItem('dropData'));
			console.log(equipmentData);
			if(equipmentData.length != 20) {
				butStr = 1;
			}
			//绘制单个div
			if(equipmentData.length != 0 && equipmentData.length != undefined) {
				huitu();
			}
			//获取滚动条当前的位置 
			function getScrollTop() {
				var scrollTop = 0;
				if(document.documentElement && document.documentElement.scrollTop) {
					scrollTop = document.documentElement.scrollTop;
				} else if(document.body) {
					scrollTop = document.body.scrollTop;
				}
				return scrollTop;
			}

			//获取当前可视范围的高度 
			function getClientHeight() {
				var clientHeight = 0;
				if(document.body.clientHeight && document.documentElement.clientHeight) {
					clientHeight = Math.min(document.body.clientHeight, document.documentElement.clientHeight);
				} else {
					clientHeight = Math.max(document.body.clientHeight, document.documentElement.clientHeight);
				}
				return clientHeight;
			}
			//获取文档完整的高度 
			function getScrollHeight() {
				return Math.max(document.body.scrollHeight, document.documentElement.scrollHeight);
			}
			var uLock=true;
			window.onscroll = function() {
//				console.log("x="+getScrollTop()+"  y="+getClientHeight()+" z="+getScrollHeight());
				if(getScrollTop() + getClientHeight() >= getScrollHeight()-6) { //ajax从这里开始
					if(butStr == 1) {
						mui.toast("没有更多数据了")
					} else {
						if (!uLock){
							return;
						}
						uLock=false;
						var keys = JSON.parse(localStorage.getItem('key'));
						var ChooseACowshedData = JSON.parse(localStorage.getItem('ChooseACowshedData'));
						var str = JSON.parse(localStorage.getItem('nainiuCode'));
						var map = {};
						if(str != 1) {
							if(ChooseACowshedData == "null") {
								map.houseID = '';
							} else {
								map.houseID = ChooseACowshedData;
							}
						}
						if (CattleSeachData != '') {
							map.searchKey = CattleSeachData;
						}
						map.key = keys;
						map.page = numberStr;
						map.size = 20;
						map.phoneType = "android";
						map.language = "zh";
						var jsonStr = JSON.stringify(map);
						var ajaxTimeoutTest = $.ajax({
							type: "POST",
							url: url_prefix + "cowAlarmList",
							dataType: 'JSON',
							 timeout: 10000,
							data: {
								'request': encryptByDES(jsonStr)
							},
							success: function(data) {
								localStorage.setItem('nainiuCode', JSON.stringify(0));
								var str1 = decryptByDESModeEBC(data["result"]); //解密
								var params = str1.replace(/\+/g, " "); //去掉字符串里的+号
								var str2 = UTFTranslate.ReChange(chineseFromUtf8Url(params)); //转utf8
								var datas = JSON.stringify(str2); //转JSON字符串
								var aa = datas.replace(/\\n/g, " "); //去掉换行
								var objs = eval('(' + aa + ')');
								var bb = eval('(' + objs + ')');
								uLock=true;
								if(bb.head.status == 1) {
									if(bb.data.length != 20) {
										butStr = 1;
									}
									if(bb.data.length == 0) {
										mui.toast("没有更多数据了");
									}
									for(var i = 0; i < bb.data.length; i++) {
										equipmentData.push(bb.data[i]);
									}
									console.log(equipmentData);
									numberStr++;
									if(bb.data.length != 0) {
										huitu();
									}
									
								} else {
									mui.alert(bb.head.info);
								}
							},
							complete: function(XMLHttpRequest, status) { //请求完成后最终执行参数
								uLock=true;
								localStorage.setItem('nainiuCode', JSON.stringify(0));　
								if(status == 'timeout') { //超时,status还有success,error等值的情况
									ajaxTimeoutTest.abort();　　　　　
									mui.alert("网络请求超时...");　　　　
								}　　
							}
						});
					}
				}
			}
			function huitu() {
				function setDiv(item,i) {
					var reproductive_status = item.reproductive_status;
					if(reproductive_status == 1){
					}
					var div = '<div class="liebiao-div"  ><div  id="' + item.cowID + '"  ><img class="liebiao-que-l" src="images/banyuan@3x.png" /><img class="liebiao-que-r" src="images/banyuan-right@3x.png" /><div class="xulieh-div" style="background: white;"><p class="xulie-p">掉落设备</p><p class="biaoqian-b">' +
						item.col2 +
						'</p></div><div><div class="liebiao-aa"><p class="liebiao-l">奶牛耳号</p><p class="liebiao-r">' +
						item.overbit +
						'</p><div class="clear"></div></div><div class="liebiao-aa"><p class="liebiao-l">掉落时间</p><p class="liebiao-r">' +
						item.alarm_time+
						'</p><div class="clear"></div></div><div class="liebiao-aa"><p class="liebiao-l">牛舍</p><p class="liebiao-r">' +
						item.cow_house_id +
						'</p><div class="clear"></div></div><div class="liebiao-aa"><p class="liebiao-l">分群</p><p class="liebiao-r">' +
						item.group_id +
						'</p><div class="clear"></div></div></div></div><div class="fqpd"><div class="fqpd-ss" style="width: 100%;"><p id="' + i + '" >'+
						item.remake+
						'</p></div></div><div class="clear"></div></div>'
					return div
				}
				function getnoApplicationData() {
					WPReason();
					var html = ''
					for(var i = 0; i < equipmentData.length; i++) {
						html += setDiv(equipmentData[i],i)
					}
					noApplicationRecord.innerHTML = html
				}
				window.onload = getnoApplicationData()
			}
			
			/*判定发情情况*/
			function OestrusInterface(map) {
				if (map==undefined){
					var map = {};
				}
				var id=document.getElementById("lu_pan_y").attributes["cow_id"].nodeValue;
				var cow_id=equipmentData[id].cowID;
				var keys = JSON.parse(localStorage.getItem('key'));
				map.key = keys;
				map.cowID = cow_id;
//				map.remark = remark.value;
// 				map.date = paramsName;
				map.phoneType = "android";
				map.language = "zh";
				console.log(map);
				var jsonStr = JSON.stringify(map);
				var ajaxTimeoutTest = $.ajax({
					type: "POST",
					url: url_prefix + "estrusDetermination",
					dataType: 'JSON',
					 timeout: 10000,
					data: {
						'request': encryptByDES(jsonStr)
					},
					success: function(data) {
						var str1 = decryptByDESModeEBC(data["result"]); //解密
						var params = str1.replace(/\+/g, " "); //去掉字符串里的+号
						var str2 = UTFTranslate.ReChange(chineseFromUtf8Url(params)); //转utf8
						var datas = JSON.stringify(str2); //转JSON字符串
						var aa = datas.replace(/\\n/g, " "); //去掉换行
						var objs = eval('(' + aa + ')');
						var bb = eval('(' + objs + ')');
						if(bb.head.status == 1) {
							hideysfaq();
							mui.alert("操作成功");
							// tjOestrus();
						} else {
							mui.alert(bb.head.info);
						}
					},
					complete: function(XMLHttpRequest, status) { //请求完成后最终执行参数
						dismissDialog();
						if(status == 'timeout') { //超时,status还有success,error等值的情况
							ajaxTimeoutTest.abort();
							mui.alert("网络请求超时...");
						}
					}
				});
			}
			//未配种原因列表
			function WPReason() {
				var keys = JSON.parse(localStorage.getItem('key'));
				var map = {};
				map.key = keys;
				map.phoneType = "android";
				map.language = "zh";
				map.ResonType=1;
				var jsonStr = JSON.stringify(map);
				var ajaxTimeoutTest = $.ajax({
					type: "POST",
					url: url_prefix + "wpReason",
					dataType: 'JSON',
					timeout: 10000,
					data: {
						'request': encryptByDES(jsonStr)
					},
					success: function(data) {
						var str1 = decryptByDESModeEBC(data["result"]); //解密
						var params = str1.replace(/\+/g, " "); //去掉字符串里的+号
						var str2 = UTFTranslate.ReChange(chineseFromUtf8Url(params)); //转utf8
						var datas = JSON.stringify(str2); //转JSON字符串
						var aa = datas.replace(/\\n/g, " "); //去掉换行
						var objs = eval('(' + aa + ')');
						var bb = eval('(' + objs + ')');
						if(bb.head.status == 1) {
							var  wpdata=bb.data;
							for (i=0;i<wpdata.length;i++) {
								var str='<div class="moban-lb">'
										+'<div class="moban-lb-l" style="width: 100%">'
										+'<a class="ziduan-mb" onclick="hideYuanYing(this)">'+wpdata[i].unmatch+'</a>'
										+'</div>';
								$("#lu_pan4").append(str);
							}
						} else {
							mui.alert(bb.head.info);
						}
					},
					complete: function(XMLHttpRequest, status) { //请求完成后最终执行参数
						dismissDialog();
						if(status == 'timeout') { //超时,status还有success,error等值的情况
							ajaxTimeoutTest.abort();
							mui.alert("网络请求超时...");
						}
					}
				});
			}
			
			
function goTop(){
			    //速度
			    var speed = 100;
			    //开启定时器
			    
			    var timer = setInterval(function(){
			        //获取滚动条的高度
			        var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
			        //设置滚动的高度
			        document.documentElement.scrollTop = document.body.scrollTop = (scrollTop - speed);
			        //清除定时器
			        speed += 30;
			        if(scrollTop <= 0){
			            clearInterval(timer);
			        }
			    },30)
			}
			
			function showLogin(){  
			    var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
			    if (scrollTop > 0) {
			    	$("#hddb").css("right","-3px");
			    } else{
			    	$("#hddb").css("right","-63px");
			    } 
			    //每秒执行一次,showTime()  
			    setTimeout("showLogin()",500);  
			}
			showLogin()
			
		</script>
	</body>

</html>
